﻿@model EvincePayroll.Data.ExperienceData
@{
   
    ViewBag.Title = "_AddExperince";
}
<script src="../../Scripts/Data_Table/jquery.dataTables.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function clereTextBoxes() {
        $('#txtEmployerName').val('');
        $('#txtContactNumber').val('');
        $('#txtEmployerAddress').val('');

        $('#txtEmployeementFrom').val('');
        $('#txtEmployeementTo').val('');
        $('#txtDesignation').val('');
        $('#txtAnnualSalary').val('');
        $('#txtDescription').val('');
        $('#formAddNewRow').hide();

    }
    $(document).ready(function () {
        setupDialogBox('addExprience', 'btnAddNewRow');
        $('#AddressError').hide();
        $('#EmployerNameError').hide();
        $('#ContactNumberError').hide();
        $('#EmployeementTypeError').hide();
        $('#EmploymentFromError').hide();
        $('#EmploymentToError').hide();
        $('#DesignationError').hide();
        $('#AnnualSalaryError').hide();
        $('#DescriptionError').hide();

        $('#formAddNewRow').hide();

        //        $('#formAddNewRow').submit(function () {
        //            $.ajax({
        //                type: "POST",
        //                url: "/Account/AddYourExperince",
        //                data: $(this).serialize(),
        //                dataType: 'json',
        //                success: function (result) {
        //                }
        //            });
        //            return false;
        //        });
        //        $('#btnAddNewRow').click(function () {
        //            $('#formAddNewRow').show();
        //            return false;

        //        });

        $('#btnCancel123').click(function () {
            clereTextBoxes();
            $('#addExprience').dialog("close");
            return false;
        });



        var oTable2 = $('#ExperinceTable').dataTable({

            "bServerSide": true,
            "sAjaxSource": "/Account/AjaxGetAddExperince",
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "aoColumns":
[
{ "sName": "ExperinceId", "sTitle": "ExperinceId", "bVisible": false, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[0]; } },
{ "sName": "EmployeeId", "sTitle": "EmployeeId", "bVisible": false, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[1]; } },
{ "sName": "EmployerName", "sTitle": "Employer Name", "sWidth": 150, "sClass": "center", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[2]; } },
{ "sName": "ContactNumber", "sTitle": "Contact", "sWidth": 70, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[3]; } },
{ "sName": "Address", "sTitle": "Address", "sWidth": 220, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[4]; } },
{ "sName": "EmployeementType", "sTitle": "Type", "sWidth": 50, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[5]; } },
{ "sName": "EmploymentForm", "sTitle": "Form", "sWidth": 50, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[6]; } },
{ "sName": "EmploymentTo", "sTitle": "To", "sWidth": 50, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[7]; } },
{ "sName": "Designation", "sTitle": "Designation", "sWidth": 100, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[8]; } },
{ "sName": "AnnualSalary", "sTitle": "Annual Salary", "sWidth": 50, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[9]; } },
{ "sName": "Action", "sTitle": "Action", "sWidth": 100, "bVisible": true, "fnRender": function (oObj) { return oObj.aData[10]; } },
]
        });
        oTable2 = $('#ExperinceTable').dataTable();
        $('#ExperinceTable').removeAttr('style');
        $("#addExprience").submit(function () {
            var errorFlag = false;
            $('.requireded').each(function () {
                if ($(this).val() == '') {
                    if ($(this).prev().attr('class') != 'error') {
                        $(this).before('<span class="error"></span>');
                    }
                    $(this).css({
                        border: '1px solid red'
                    });
                    errorFlag = true;
                } else {
                    if ($(this).prev().attr('class') == 'error') {
                        $(this).prev().remove();
                        $(this).removeAttr('style');
                    }
                }
            });

            if (errorFlag != true) {
                var ajaxUrl;
                var experienceId = $('#experinceId').val();
                if (experienceId != '') {
                    ajaxUrl = '/Account/AddYourExperince?flag=1' + '&experinceId=' + experienceId;
                }
                else {
                    ajaxUrl = '/Account/AddYourExperince';
                }

                $.ajax({
                    type: "POST",
                    url: ajaxUrl,
                    data: $(this).serialize(),
                    dataType: 'json',
                    success: function (result) {
                        var oTable2 = $('#ExperinceTable').dataTable();
                        oTable2.fnDraw();
                        $('#addExprience').dialog("close");
                        clereTextBoxes();
                        return false;
                    }
                });
            }
            if (errorFlag == true) {
                return false;
            }
            return false;

        });




    });
    function EditExperience(experienceId) {
        $("#addExprience").dialog("open");

        $.ajax({
            type: "POST",
            url: "/Account/EditExperience?experienceId=" + experienceId,
            success: function (result) {
                var value = result.result;
                $('#txtEmployerName').val(value.EmployerName);
                $('#txtContactNumber').val(value.ContactNumber);
                $('#txtEmployerAddress').val(value.Address);
                $('#txtEmployeementType').val(value.EmployeementType);
                $('#txtEmployeementFrom').val(value.EmploymentFrom);
                $('#txtEmployeementTo').val(value.EmploymentTo);
                $('#txtDesignation').val(value.Designation);
                $('#txtAnnualSalary').val(value.AnnualSalary);
                $('#txtDescription').val(value.Description);
                $('#experinceId').val(value.ExperienceId);
                return false;
            }
        });

    }
    function DeleteExperience(experienceId) {

        var temp = confirm('Are you sure want to delete?');
        if (temp == true) {
            $.ajax({
                type: "POST",
                url: "/Account/DeleteExperience?experienceId=" + experienceId,
                success: function (result) {
                    var oTable2 = $('#ExperinceTable').dataTable();
                    oTable2.fnDraw();
                   // $('#ExperinceTable').width('auto');
                    return false;
                }
            });
        }
    }
</script>
<div class="block">
    <button id="btnAddNewRow" class="btn btn-orange" value="Ok" style="float: left">
        Add Work Experince</button>
    &nbsp;&nbsp;&nbsp;
    <input type="hidden" id="experinceId" />
    <table class="data display datatable" id="ExperinceTable">
        <thead>
            <tr>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
                <th>
                </th>
            </tr>
        </thead>
    </table>
                     <form id="addExprience" method="post" action="AddYourExperince" title="Add Exprience">
    
    <table class="form">
            <tr>
                <th colspan="2">
                    Add Your exprience here.
                </th>
            </tr>
            <tr>
                <td class="left">
                    <label class="center">
                        Employer Name</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.EmployerName, new { id = "txtEmployerName", @class = "requireded" })
                </td>
            </tr>
            <tr>
                <td class="left">
                    <label class="center">
                        Contact Number</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.ContactNumber, new { id = "txtContactNumber", @class = "requireded" })
                    <span class="error" id="ContactNumberError">*</span>
                </td>
            </tr>
            <tr>
                <td class="left">
                    <label class="center">
                        Employer Address</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.Address, new { id = "txtEmployerAddress", @class = "requireded" })
                    <span class="error" id="AddressError">*</span>
                </td>
            </tr>
            <tr>
                <td class="left">
                    <label class="center">
                        Employment Type</label>
                </td>
                <td class="right">
                    @Html.DropDownListFor(m => m.EmployeementType, new SelectList(ViewBag.EmploymentType as System.Collections.IEnumerable, "ParamId", "ParamValue"), "", new { id = "txtEmployeementType", @class = "requireded" })
                    <span class="error" id="EmployeementTypeError">*</span>
                </td>
            </tr>
            <tr>
                <td class="left">
                    <label class="center">
                        Employment From</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.EmploymentFrom, new { id = "txtEmployeementFrom", @class = "requireded" })
                    <span class="error" id="EmploymentFromError">*</span>
                </td>
            </tr>
            <tr id="leaveTypeFrom">
                <td class="left">
                    <label>
                        Employment To</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.EmploymentTo, new { id = "txtEmployeementTo", @class = "requireded" })
                    <span class="error" id="EmploymentToError">*</span>
                </td>
            </tr>
            <tr id="leaveTypeTo">
                <td class="left">
                    <label>
                        Designation</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.Designation, new { id = "txtDesignation", @class = "requireded" })
                    <span class="error" id="DesignationError">*</span>
                </td>
            </tr>
            <tr>
                <td class="left">
                    <label>
                        Annual Salary</label>
                </td>
                <td class="right">
                    @Html.TextBoxFor(m => m.AnnualSalary, new { id = "txtAnnualSalary", @class = "requireded" })
                    <span class="error" id="AnnualSalaryError">*</span>
                </td>
            </tr>
            <tr>
                <td class="left" style="vertical-align: top;">
                    <label>
                        Description</label>
                </td>
                <td class="right">
                    @Html.TextAreaFor(m => m.Description, new { id = "txtDescription", @class = "requireded", @cols = "40", @rows = "4" })
                    <span class="error" id="DescriptionError">*</span>
                </td>
            </tr>
            <tr>
                <td align="center" colspan="2">
                    <button class="btn btn-orange" id="btnSubmitExperience">
                        Submit</button>
                    <button class="btn btn-orange" id="btnCancel123">
                        Cancel</button>
                </td>
            </tr>
        </table>
</form>
       
                </div>
           
